function DayAssistant(){
	
}

DayAssistant.prototype.setup = function(){
	
		/*this.drawerModel = {myOpenProperty:false};
		this.controller.setupWidget('recipeDrawer', {property:'myOpenProperty'}, this.drawerModel);
		this.drawer = this.controller.get('recipeDrawer');
		
		// Hook up the toggle button:
		this.controller.listen('toggleDrawerButton', Mojo.Event.tap, this.toggleDrawer.bindAsEventListener(this));	*/	
			
	  this.controller.setupWidget("cupPicker",
         this.attributes = {
             label: " ",
             min: 0,
             max: 50

         },
         this.model = {
             value: numberOfCups
         });
	this.controller.listen('cupPicker', Mojo.Event.propertyChange, this.cupsPropertyChanged.bindAsEventListener(this));
  	this.controller.setupWidget("lemonPicker",
         this.attributes = {
             label: " ",
             min: 0,
             max: 5

         },
         this.model = {
             value: numberOfLemons
         });
	this.controller.listen('lemonPicker', Mojo.Event.propertyChange, this.lemonPropertyChanged.bindAsEventListener(this));	
	
		this.controller.setupWidget("sugarPicker",
         this.attributes = {
             label: " ",
             min: 0,
             max: 3

         },
         this.model = {
             value: numberOfSuger
         });
	this.controller.listen('sugarPicker', Mojo.Event.propertyChange, this.sugerPropertyChanged.bindAsEventListener(this));	
	
	this.controller.setupWidget("pricePicker",
         this.attributes = {
             label: " ",
             min: 1,
             max: 150

         },
         this.model = {
             value: price * 100
         });
	this.controller.listen('pricePicker', Mojo.Event.propertyChange, this.pricePropertyChanged.bindAsEventListener(this));	
	
	this.controller.setupWidget("adPicker",
         this.attributes = {
             label: " ",
             min: 0,
             max: 15

         },
         this.model = {
             value: numberOfAds
         });
	this.controller.listen('adPicker', Mojo.Event.propertyChange, this.adPropertyChanged.bindAsEventListener(this));	
	
	
	this.buttonAttributes = {};	
	
	this.CommandMenuAttributes = {
										spacerHeight: 25,
										menuClass: 'no-fade',
									 };
		
		this.CommandMenuModel = {
									visible: true,
									items: [{}, {
									  		items: [{
													label: 'Continue',
													command: 'report'
												}]
											}, {}
											]
								};
	this.controller.setupWidget(Mojo.Menu.commandMenu, this.CommandMenuAttributes, this.CommandMenuModel);
	//this.controller.setupWidget("goButton", this.buttonAttributes, this.buttonModel);
	//Mojo.Event.listen(this.controller.get('goButton'), Mojo.Event.tap, this.reportGame.bind(this));
	this.controller.setupWidget(Mojo.Menu.appMenu,
       this.attributes = {
                omitDefaultItems: true
            },
    this.model = {
        visible: true,
        items: [ 
            {label: "Restart", command: 'restart'},
			 Mojo.Menu.editItem,
            { label: "Preferences", command: 'do-myPrefs' },
            { label: "Help", command: 'do-myHelp' }

        ]
    });

	var t = window.setTimeout('gameEngine()', 50);
}


DayAssistant.prototype.activate = function(event) {
	messageTrue = false;
	var sugerUp = false;
	var lemonUp = false;
	pricePerCup = (pricePerLemon * numberOfLemons) + (pricePerSuger * numberOfSuger);
	var a = randRange(1, 10);
	chanceOfRain = randRange(1, 10) * 10;
	temperature = randRange(60, 100);
	//expenses = (Math.floor((((pricePerCup / 100) * numberOfCups) + priceOfAds) * 100)) / 100;
	if (dayNumber >= 5){
		if (a == 5){
			pricePerSuger += 1;
			sugerUp = true;
		}else if (a == 6){
			pricePerLemon += 1;
			lemonUp = true;
		}
	}
	
	if (sugerUp == true){
		$(message).innerHTML = "The price of sugar has gone up by 1 cent";
		messageTrue = true;
	}
	if (lemonUp == true){
		$(message).innerHTML = "The price of lemons has gone up by 1 cent";
		messageTrue = true;
	}
	
	//$(message).innerHTML = difficultySettings;
	
	//numberOfCups = this.cupSlider.value;
	
	expenses = (Math.floor((((pricePerCup / 100) * numberOfCups) + priceOfAds) * 100)) / 100;
	
	/* put in event handlers here that should only be in effect when this scene is active. For
	   example, key handlers that are observing the document */
	 price = Math.floor(price * 100) / 100;
	 $(dayCounter).innerHTML = "Day " + dayNumber;
	 $(costPerCup).innerHTML = "Each cup will cost you " + pricePerCup + " cents";
	 /*$(sugerNumber).innerHTML = "You are putting in " + numberOfSuger + " sugar cubes";
	 $(lemonNumber).innerHTML = "You are putting in " + numberOfSuger + " lemon slices";
	 $(priceNumber).innerHTML = "You are charging $" + price + " for each cup"; 
	 $(adNumber).innerHTML = "You are making " + numberOfAds + " advertising signs";*/
	 $(adPrice).innerHTML = "Advertising is costing you $" + priceOfAds;
	 $(fundsDisplay).innerHTML = "Funds: $" + money;
	 $(expensesDisplay).innerHTML = "Expenses: $" + expenses;
	 $(rainDisplay).innerHTML = chanceOfRain + "% chance of rain";
	 $(tempDisplay).innerHTML = "Forcasted temp. is " + temperature + " degrees";
}
function gameEngine(){
	//$(message).innerHTML = document.documentElement.dayCounter.top;
}

DayAssistant.prototype.cupsPropertyChanged = function(event){
	//$(message).innerHTML = event;
	numberOfCups = event.value;
	expenses = (Math.floor((((pricePerCup / 100) * numberOfCups) + priceOfAds) * 100)) / 100;
	$(expensesDisplay).innerHTML = "Expenses: " + expenses;
}

DayAssistant.prototype.reportGame = function(event){
	if (money < expenses){
		//$(message).innerHTML = "hello2";
	//	Mojo.Controller.errorDialog("You do not have enough money for that")
		//var callback = this.activate.bind(this);
	//	Mojo.Controller.getAppController();
	 Mojo.Controller.errorDialog("You Don't have enough money for that.");
		

	}else if (numberOfCups == 0){
		 Mojo.Controller.errorDialog("You need to make at least one cup");
	}else{
		//$(message).innerHTML = "hello1";
		Mojo.Controller.stageController.swapScene('report');
	}
}

function restartGame(){
	// restart all the global variables
		var startMoney;
	 switch (difficultySettings){
		case "easy":
		   	//bonus = 0;
			startMoney = 7.50;
			break;
		case "medium":
			//bonus = 1.50;
			startMoney = 5.00;
			break;
		case "hard":
			//bonus = 2.50;
			startMoney = 3.00;
			break;
	   }
	 dayNumber = 1;
	// numberOfDays = 10;
	 pricePerSuger = 5;
	 pricePerLemon = 6;
	 numberOfLemons = 1;
	 numberOfSuger = 1;
	 numberOfCups = 1;
	 numberOfAds = 1;
	 priceOfAds = 0.15;
	 price = 0.01;
	 pricePerCup = 0;
	 money = startMoney;
	 expenses = 0;
	 chanceOfRain = 0;
	 temperature = 0;
	 messageTrue = false;
	 sugerMessage = "";
	 sugerGood = false;
	 cupsSoldNumber = 0;
	// difficultySettings = "medium";
	// daysSettings = 10;
	Mojo.Controller.stageController.swapScene('start');
}

DayAssistant.prototype.handleCommand = function (event) {
	//$(message).innerHTML = event.command;
	/*this.controller=Mojo.Controller.stageController.activeScene();
    if (event.type == Mojo.Event.commandEnable &&
	    (event.command == Mojo.Menu.helpCmd)) {
         event.stopPropagation(); // enable help. now we have to handle it
    }
	 if (event.type == Mojo.Event.commandEnable &&
	    (event.command == Mojo.Menu.prefsCmd)) {
         event.stopPropagation(); // enable preferences. now we have to handle it
    }

	console.log("RIGHT HERE");*/
	if (event.type == Mojo.Event.command) {
		var youOrdered = "";
		console.log("SettingsSceneAssistant::handleCommand(): Got command: " + event.command);
		//$(message).innerHTML="hello";
		switch (event.command) {			
			// another built-in menu item, but we've enabled it (see below in this method)
			// so now we have to handle it:
			case "do-myHelp":
				Mojo.Controller.stageController.pushScene('support');
				break;
			case "do-myPrefs":
				Mojo.Controller.stageController.pushScene('settings');
				break;
			case "report":
				this.reportGame();
				break;
			case "restart":
				restartGame();
				break;
		}
		if (event.command.capitalize() == 'report'){
			$(message).innerHTML="hi";
		}
	}
}

DayAssistant.prototype.lemonPropertyChanged = function(event){
	numberOfLemons = event.value;
	pricePerCup = (pricePerLemon * numberOfLemons) + (pricePerSuger * numberOfSuger);
	//$(lemonNumber).innerHTML = "You are putting in " + event.value + " lemon slices";
	$(costPerCup).innerHTML = "Each cup will cost you " + pricePerCup + " cents";
	expenses = (Math.floor((((pricePerCup / 100) * numberOfCups) + priceOfAds) * 100)) / 100;
	$(expensesDisplay).innerHTML = "Expenses: " + expenses;
}

DayAssistant.prototype.sugerPropertyChanged = function (event){
	numberOfSuger = event.value;
	//$(sugerNumber).innerHTML = "You are putting in " + event.value + " sugar cubes";
	pricePerCup = (pricePerLemon * numberOfLemons) + (pricePerSuger * numberOfSuger);
	$(costPerCup).innerHTML = "Each cup will cost you " + pricePerCup + " cents";
	expenses = (Math.floor((((pricePerCup / 100) * numberOfCups) + priceOfAds) * 100)) / 100;
	$(expensesDisplay).innerHTML = "Expenses: " + expenses;
}

DayAssistant.prototype.pricePropertyChanged = function(event){
	price = event.value / 100;
	price = Math.floor(price * 100) / 100;
	//$(priceNumber).innerHTML = "You are charging $" + price + " for each cup";
}
													   
DayAssistant.prototype.adPropertyChanged = function(event){
	numberOfAds = event.value;
	priceOfAds = numberOfAds * .15;
	//$(adNumber).innerHTML = "You are making " + event.value + " advertising signs"
	var display = Math.floor(priceOfAds * 100) / 100;
	$(adPrice).innerHTML = "Advertising is costing you $" + display;
	expenses = (Math.floor((((pricePerCup / 100) * numberOfCups) + priceOfAds) * 100)) / 100;
	$(expensesDisplay).innerHTML = "Expenses: " + expenses;
}

DayAssistant.prototype.deactivate = function(event) {
	/* remove any event handlers you added in activate and do any other cleanup that should happen before
	   this scene is popped or another scene is pushed on top */
}

DayAssistant.prototype.cleanup = function(event) {
	/* this function should do any cleanup needed before the scene is destroyed as 
	   a result of being popped off the scene stack */
}

function randRange (small, big){
	return Math.floor(Math.random() * (small - big) + big);
}